module two {
	export class SharePage extends BaseComponent {
		public constructor() {
			super("SharePage");
		}
		public gp: eui.Group;

		public star: eui.Group;
		public gp_1: eui.Group;
		public txt_name_1: eui.Label;
		public txt_title_1: eui.Label;
		public gp_2: eui.Group;
		public txt_name: eui.Label;
		public txt_name_2: eui.Label;
		public txt_title_2: eui.Label;
		public btn_cancel: eui.Button;

		public list_ewm: eui.List;

		protected created(): void {
			super.created();

			this.btn_cancel.visible = false;
			this.star.removeChildren();


			this.gp_1.alpha = 0;
			this.gp_2.alpha = 0;
			egret.Tween.get(this.gp_1).to({
				alpha: 1
			}, 1000);

			two.addTap(this.btn_cancel, () => {
				two.changePage("map");
			})

			let ac = this.list_ewm.dataProvider as eui.ArrayCollection;
			ac.removeAll();
			let l: any[] = RES.getRes("gameCfg_json")['ewm'];
			for (let i = 0; i < l.length; i++) {
				ac.addItem(l[i]);
			}
		}

		public resetJewelry(jewId: string): void {
			let jewCfg = JewelryConfig.getConfigById(jewId);
			let starCfg = StarConfig.getConfigById(jewCfg.star);

			two.shareJepage(true, starCfg.id);

			this.txt_title_1.text = starCfg.title;
			this.txt_name_1.text = "属于你的" + starCfg.name;

			this.txt_name.text = User_getSignatureProxy.getInstance().getResponse().name + " 在星图里点亮了";
			this.txt_name_2.text = starCfg.name;
			this.txt_title_2.text = starCfg.title;

			var frames = {
				open: [],
			};
			for (let i = 1; i <= jewCfg.count[0]; i++) {
				frames.open.push("" + i);
			}
			let mc = new one.DynamicFrames(frames, jewCfg.star + "_open_" + jewCfg.icon, "jpg");
			this.star.addChild(mc);
			mc.play('open', 1);

			mc.once(egret.Event.COMPLETE, () => {
				this.gp_1.visible = false;
				egret.Tween.get(this.gp_2).to({
					alpha: 1
				}, 1000).call(() => {
					this.btn_cancel.visible = true;
					this.changeToWebImage();
				});
			}, null);
		}

		private changeToWebImage(): void {
			let rect = new egret.RenderTexture();
			rect.drawToTexture(this.gp, new egret.Rectangle(0, 0, this.gp.width, this.gp.height - 50));
			let webNode = new one.WebImage();
			webNode.src = rect.toDataURL("image/png");
			this.addChild(webNode);
			webNode.width = this.gp.width;
			webNode.height = this.gp.height - 50;

			// this.gp.visible = false;
		}
	}

	two.setClassMap("share", "two.SharePage");
}